﻿using System;
using System.Collections;
using System.Collections.Generic;
using Const;
using Entitas;
using UnityEngine;

public class EliminateAudioSystem : ReactiveSystem<GameEntity>
{
    public EliminateAudioSystem(Contexts context) : base(context.game)
    {
    }

    protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context)
    {
        return context.CreateCollector(GameMatcher.ComponentsEliminate);
    }

    protected override bool Filter(GameEntity entity)
    {
        return entity.hasComponentsItemEffectState 
               && entity.componentsEliminate.isEliminate;
    }

    protected override void Execute(List<GameEntity> entities)
    {
        foreach (GameEntity entity in entities)
        {
            switch (entity.componentsItemEffectState.EffectState)
            {
                case ItemEffectName.NONE:
                    entity.ReplaceComponentsAudio(AudioName.NormalBomb.ToString());
                    break;
                case ItemEffectName.ELIMINATE_SAME_COLOR:
                    entity.ReplaceComponentsAudio(AudioName.SpecialBomb.ToString());
                    break;
                case ItemEffectName.ELIMINATE_HORIZONTAL:
                    entity.ReplaceComponentsAudio(AudioName.SpecialBomb.ToString());
                    break;
                case ItemEffectName.ELIMINATE_VERTICAL:
                    entity.ReplaceComponentsAudio(AudioName.SpecialBomb.ToString());
                    break;
                case ItemEffectName.EXPLODE:
                    entity.ReplaceComponentsAudio(AudioName.SpecialBomb.ToString());
                    break;
                
            }
        }
    }
}

public class FallAudioSystem : ReactiveSystem<GameEntity>
{
    public FallAudioSystem(Contexts context) : base(context.game)
    {
    }

    protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context)
    {
        return context.CreateCollector(GameMatcher.ComponentsFallState);
    }

    protected override bool Filter(GameEntity entity)
    {
        return entity.hasComponentsFallState
               && entity.componentsFallState.state == fallState.FALL;
    }

    protected override void Execute(List<GameEntity> entities)
    {
        foreach (GameEntity entity in entities)
        {
           Debug.Log("fallAudio");
            entity.ReplaceComponentsAudio(AudioName.Fall.ToString());
        }
    }
}
